package com.qf.smsplatform.controller;
/*2021/10/29*/

import com.github.pagehelper.PageInfo;
import com.qf.smsplatform.dto.R;
import com.qf.smsplatform.pojo.TAdminUser;
import com.qf.smsplatform.pojo.TSmsTemplate;
import com.qf.smsplatform.service.TSmsTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @YuTao
 */
@RestController
@RequestMapping("/template")
public class TSmsTemplateServiceController {

    private TSmsTemplateService tSmsTemplateService;
    @Autowired
    public void settSmsTemplateService(TSmsTemplateService tSmsTemplateService) {
        this.tSmsTemplateService = tSmsTemplateService;
    }
    @RequestMapping("/insert")
    public R insetTemplate(@RequestBody TSmsTemplate tSmsTemplate, HttpSession session){
        TAdminUser user = (TAdminUser)session.getAttribute("user");
        tSmsTemplate.setCreater(user.getId());
        tSmsTemplate.setOwntype(user.getType());
        tSmsTemplateService.insetTSmsTemplate(tSmsTemplate);
        return R.setOk();
    }
    @RequestMapping("/update")
    public R updateTemplate(@RequestBody TSmsTemplate tSmsTemplate,HttpSession session){
        TAdminUser user = (TAdminUser)session.getAttribute("user");
        tSmsTemplate.setCreater(user.getId());
        tSmsTemplate.setOwntype(user.getType());
        tSmsTemplateService.updateTSmsTemplate(tSmsTemplate);
        return R.setOk();
    }

    @RequestMapping("/delete")
    public R deleteTemplate(Long id){
        tSmsTemplateService.deleteTemplate(id);
        return R.setOk();
    }

    @RequestMapping("/page")
    public R seletPage(int pageNum,int pageSize){

        PageInfo<TSmsTemplate> pageInfo = tSmsTemplateService.selectPage(pageNum, pageSize);
        return R.setOk(pageInfo);

    }
}
